<?php
/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2019/7/30
 * Time: 14:29
 */

namespace app\api\model;


use think\Model;

class Login extends Model
{
    protected $error;


    function getError()
    {
        return $this->error;
    }

    function login($data, $type = '')
    {
        $user = $this->field('id,password')->where([$type => $data['username']])->find();
        if (!$user) {
            $this->error = '用户不存在';
            return false;
        }
        $data['password'] =strtoupper(sha1($data['password'].$user['id'].$user['code']));
        if ($user['password'] != $data['password']) {
            $this->error = '密码错误';
            return false;
        }

        return $user['id'];
    }
}